/* 数组原型修改 */
let arrProto = Array.prototype
let newArrProto = Object.create(arrProto)
let arrMethods = ["push", "splice", "sort", "pop", "shift", "unshift", "reverse"]
arrMethods.forEach(method => {
    Object.defineProperty(newArrProto, method, {
        value: function (...args) {
            let ret = arrProto[method].apply(this, args), inserted
            switch (method) {
                case "push":
                    inserted = args;
                    break;
                case "unshift":
                    inserted = args;
                    break;
                case "splice":
                    inserted = args.slice(2)
            }
            // console.log(method, 'changed', args, "__ob__: ", this.__ob__.dep)
            if (inserted) {
                // console.log(this.__ob__)
                // 对新增的元素也进行响应式处理
                this.__ob__.handleArrElement(inserted)
            }
            // 通知 使用当前数组的元素进行数据更新
            // console.dir(this.__ob__.dep.watchers)
            this.__ob__.dep.notify()
            return ret
        },
        enumerable: false,
        configurable: true,
        writable: true
    })
});

export default function protoArguments(data) {
    data.__proto__ = newArrProto
}